package com.liang.common.handler;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Configuration
public class MyAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException {
//
//        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
//        response.setHeader("content-Type","application/json;charset=utf-8");
//        PrintWriter writer = response.getWriter();
//        writer.write("权限不足,请联系管理员");
//        writer.flush();
//        writer.close();
        response.sendError(HttpServletResponse.SC_FORBIDDEN, "权限不足,请联系管理员");
    }
}
